<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="健康状况" prop="healthType">
        <el-select v-model="queryParams.healthType" placeholder="请选择健康状况" clearable style="width: 140px">
          <el-option
            v-for="dict in dict.type.health_stock_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="中高风险" prop="middleHigh">
        <el-select v-model="queryParams.middleHigh" placeholder="请选择中高风险" clearable style="width: 140px">
          <el-option
            v-for="dict in dict.type.health_stock_middle"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="接触确诊" prop="diagnosis">
        <el-select v-model="queryParams.diagnosis" placeholder="请选择接触确诊" clearable style="width: 140px">
          <el-option
            v-for="dict in dict.type.health_stock_diagnosis"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="境外返回" prop="returnInfo">
        <el-select v-model="queryParams.returnInfo" placeholder="请选择境外返回" clearable style="width: 140px">
          <el-option
            v-for="dict in dict.type.health_stock_diagnosis"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['health:healthclockinfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['health:healthclockinfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="healthclockList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column label="姓名" align="center" prop="username" />
      <el-table-column label="健康状况" align="center" prop="healthType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.health_stock_type" :value="scope.row.healthType"/>
        </template>
      </el-table-column>
      <el-table-column label="体温" align="center" prop="temperature" />
      <el-table-column label="中高风险" align="center" prop="middleHigh">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.health_stock_middle" :value="scope.row.middleHigh"/>
        </template>
      </el-table-column>
      <el-table-column label="接触确诊" align="center" prop="diagnosis">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.health_stock_diagnosis" :value="scope.row.diagnosis"/>
        </template>
      </el-table-column>
      <el-table-column label="境外返回" align="center" prop="returnInfo">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.health_stock_diagnosis" :value="scope.row.returnInfo"/>
        </template>
      </el-table-column>
      <el-table-column label="打卡位置" align="center" prop="address" />
      <el-table-column label="打卡时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
          >详细</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />



    <!-- 添加或修改打卡信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="dataForm" :model="dataForm" :rules="rules" label-width="80px">
        <el-form-item label="健康状况" prop="healthType">
          {{ dataForm.healthType === 0 ? '正常' : '异常' }}
        </el-form-item>
        <el-form-item label="体温" prop="temperature">
          {{dataForm.temperature}}
        </el-form-item>
        <el-form-item label="中高风险" prop="middleHigh">
          {{ dataForm.middleHigh == 0 ? '低风险' : (dataForm.middleHigh == 1 ? '中风险' : '高风险') }}
        </el-form-item>
        <el-form-item label="接触确诊" prop="diagnosis">
          {{ dataForm.healthType === 0 ? '否' : '是' }}
        </el-form-item>
        <el-form-item label="境外返回" prop="returnInfo">
          {{ dataForm.healthType === 0 ? '否' : '是' }}
        </el-form-item>
        <el-form-item label="打卡位置" prop="address">
          {{dataForm.address}}
        </el-form-item>
        <el-form-item label="打卡时间" prop="createTime">
          {{dataForm.createTime}}
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { listHealthclock, getHealthclock, delHealthclock, addHealthclock, updateHealthclock } from "@/api/health/healthclock";

export default {
  name: "Healthclockinfo",
  dicts: ['health_stock_middle', 'health_stock_type', 'health_stock_diagnosis'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 打卡信息表格数据
      healthclockList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      dataForm:{},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        username: null,
        healthType: null,
        temperature: null,
        middleHigh: null,
        diagnosis: null,
        returnInfo: null,
        address: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //查看按钮
    handleView(row) {
      this.open = true
      this.dataForm = row
    },
    /** 查询打卡信息列表 */
    getList() {
      this.loading = true;
      listHealthclock(this.queryParams).then(response => {
        this.healthclockList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getHealthclock(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改报告信息";
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        username: null,
        healthType: null,
        temperature: null,
        middleHigh: null,
        diagnosis: null,
        returnInfo: null,
        address: null,
        createTime: null,
        updateTime: null,
        deptId: null,
        isDelete: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateHealthclock(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addHealthclock(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除打卡信息编号为"' + ids + '"的数据项？').then(function() {
        return delHealthclock(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('health/healthclockinfo/export', {
        ...this.queryParams
      }, `healthclockinfo_${new Date().getTime()}.xlsx`)
    }
  },
  watch: {
    // 如果路由有变化，会再次执行clear方法
    // "$route": "clear",
    $route(to , from){
      this.$router.go(0)
    }
  }
};
</script>

<style lang="scss" scoped>
  .group{
    text-align: center;
  }
  .content{
    margin: 25px auto;
  }
  // 级联下拉框单选 文字选中样式
  .selectArea {
    .el-radio {
      width: 100%;
      height: 100%;
      z-index: 10;
      position: absolute;
    }
    .is-disabled {
      cursor: not-allowed;
    }
    .el-radio__input {
      visibility: hidden;
    }
  }
</style>
